package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.popwindow.BasicPopmodule;

import butterknife.internal.DebouncingOnClickListener;

public class PopPackages extends BasicPopmodule {

    private Context mContext;

    private PopPackagesListener mPoplistener;

    public PopPackages(Context context, PopPackagesListener l){
        this.mContext=context;
        this.mPoplistener=l;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_packages_module, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        View mVwPopBlank=(View)mContentView.findViewById(R.id.vw_pop_blank);
        View mVwPopBlank1=(View)mContentView.findViewById(R.id.vw_pop_blank1);
        final EditText mEtPackagesSck=(EditText)mContentView.findViewById(R.id.et_packages_sck);
        RelativeLayout mDisagree=(RelativeLayout)mContentView.findViewById(R.id.pop_protocol_disagree);
        RelativeLayout mAgree=(RelativeLayout)mContentView.findViewById(R.id.pop_protocol_agree);
        mDisagree.setOnClickListener(new DebouncingOnClickListener() {
            @Override
            public void doClick(View view) {
               mPopwindows.dismiss();
            }
        });
        mAgree.setOnClickListener(new DebouncingOnClickListener() {
            @Override
            public void doClick(View view) {
                if (!TextUtils.isEmpty(mEtPackagesSck.getText().toString())){
                    mPoplistener.PopAgree(mEtPackagesSck.getText().toString());
                }else{
                    Toast toast = Toast.makeText(mContext, "请输入兑换码", Toast.LENGTH_SHORT);
                    ToastUtils.showMyToast(toast, 3000);
                }
            }
        });
        mVwPopBlank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mVwPopBlank1.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });


    }


    public interface PopPackagesListener {
        void PopAgree(String RedemptionCode);
    }
}
